/*
 * File:   Michalewicz.h
 * Author: jcrada
 *
 * Created on 28 April 2011, 2:49 PM
 */

#ifndef ECB_MICHALEWICZ_H
#define	ECB_MICHALEWICZ_H

#include "ecb/base/Problem.h"
#include <cmath>

namespace ecb {

    /* Source:
     * @inproceedings{bf:michalewicz,
       author={Bersini, H. and Dorigo, M. and Langerman, S. and Seront, G. and Gambardella, L.},
       booktitle={Evolutionary Computation, 1996., Proceedings of IEEE International Conference on},
     *  title={Results of the first international contest on evolutionary optimisation (1st ICEO)},
       year={1996},
       month={may},
       volume={},
       number={},
       pages={611 -615}}
     *
     * Range: 0-Pi
     */

    class Michalewicz : public Problem {
    private:
        scalar _m;
    public:

        Michalewicz(const std::string& id = "Michalewicz", const std::string& name = "Michalewicz",
                int dimensions = 0, scalar minimum = -0, scalar maximum = M_PI,
                scalar m = 10, bool minimization = true) :
        Problem(id, name, dimensions, minimum, maximum, minimization), _m(m) { }

        void setM(scalar m) {
            this->_m = m;
        }

        scalar getM() const {
            return this->_m;
        }

        scalar f(const std::vector<scalar>& x) {
            scalar result = 0;
            for (size_t i = 0; i < x.size(); ++i) {
                result += std::sin(x[i]) * std::pow(std::sin((i + 1) * x[i] * x[i] / M_PI), 2 * _m);
            }
            return result;
        }
    };
}

#endif	/* ECB_MICHALEWICZ_H */

